package com.tc168.cp306.b06;

import android.app.Application;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

import com.litesuits.common.assist.Network;
import com.tc168.cp306.b06.Utils.ToastUtil;
import com.tc168.cp306.b06.Utils.copyDbFile;
import com.tc168.cp306.b06.gen.DaoMaster;
import com.tc168.cp306.b06.gen.DaoSession;

public class MyApplication extends Application {

    public static MyApplication instances;

    public static Context context;
    private static final String TAG = "Myapplaction";
    private static DaoSession mDaoSession;
    private static DaoSession mDaoSession2;


    @Override
    public void onCreate() {
        super.onCreate();
        context = this;

        initGreenDao();
    }

    private void initGreenDao() { //创建数据库mydb.db
        //从资源文件中复制数据库
        copyDbFile copy = new copyDbFile();
        copy.fuzhiDbFile(this, "persondb.db");


        //数据库创建了就不会再次创建
        DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "persondb.db");
        //获取可写数据库
        SQLiteDatabase database = helper.getWritableDatabase();
        //获取数据库对象
        DaoMaster daoMaster = new DaoMaster(database);
        //获取Dao对象管理者
        mDaoSession = daoMaster.newSession();


        DaoMaster.DevOpenHelper helper2 = new DaoMaster.DevOpenHelper(this, "useraa.db");
        //获取可写数据库
        SQLiteDatabase database2 = helper2.getWritableDatabase();
        //获取数据库对象
        DaoMaster daoMaster2 = new DaoMaster(database2);
        //获取Dao对象管理者
        mDaoSession2 = daoMaster2.newSession();


    }

    public static DaoSession getmDaoSession() {
        return mDaoSession;
    }


    public static DaoSession getmDaoSessiontwo() {
        return mDaoSession2;
    }

}